local ma__yingtai = fk.CreateSkill {
  name = "ma__yingtai",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable{
  ["ma__yingtai"] = "萦台",
  [":ma__yingtai"] = "限定技，出牌阶段，你可以交给一名其他角色至少X张牌（X为其体力值），然后获得〖英魂〗，若如此做，你死亡时可以令一名其他角色加1点体力上限、回复1点体力并获得〖英魂〗。",

  ["#ma__yingtai-invoke"] = "萦台：交给其他角色不少于其体力值数量的牌并获得〖英魂〗",
  ["#ma__yingtai-dead"] = "萦台：令一名其他角色加体力上限并获得〖英魂〗！",
}

ma__yingtai:addEffect("active", {
  anim_type = "support",
  prompt = "#ma__yingtai-invoke",
  min_card_num = 1,
  target_num = 1,
  include_equip = true,
  can_use = function(self, player)
    return player:usedSkillTimes(ma__yingtai.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.TrueFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and to_select.hp <= #selected_cards
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = effect.cards
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, ma__yingtai.name, nil, false, player)
    room:addPlayerMark(player, ma__yingtai.name)
    room:handleAddLoseSkills(player, "yinghun")
  end,
})

ma__yingtai:addEffect(fk.Death, {
  anim_type = "negative",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark(ma__yingtai.name) ~= 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = ma__yingtai.name,
      prompt = "#ma__yingtai-dead",
      cancelable = true,
    })
    event:setCostData(self, {tos = tos})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self).tos
    for _, p in ipairs(tos) do
      if not p.dead then
      room:changeMaxHp(p, 1)
        if p:isAlive() and p:isWounded() then
          room:recover{
            who = p,
            num = 1,
            recoverBy = p,
            skillName = ma__yingtai.name,
          }
        end
      room:handleAddLoseSkills(p, "yinghun")
      end
    end
  end,
})

return ma__yingtai
